<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2024/4/19
 * Time: 13:52
 */

namespace app\common\service;

use app\common\enum\SetUrlCrawler_statusEnum;
use app\models\SetUrlCrawler;
use yii\queue\JobInterface;
use yii\queue\Queue;

class MyJob implements JobInterface
{
    public $id;

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param $id
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }

    public function __construct($id)
    {
        $this->setId($id);
    }

    /**
     * @param Queue $queue
     * @return bool
     */
    public function execute($queue)
    {
        $obj = new GptCrawler();
        /**
         * @var $row SetUrlCrawler
         */
        $row = SetUrlCrawler::find()->andWhere(['status'=>SetUrlCrawler_statusEnum::UNDO])->one();
        if(empty($row)){
            return false;
        }
        return $obj->run($row);
    }

}